a=int(input())
l=0
if a<999 or a>10000:
     print('0')

     exit()
else:
    a1=a
    a2=a//10
    a3=a//100
    a4=a//1000
    a5=a%1000
    a6=a%1000//10
    a7=a%1000//100
    a8=a%100
    a9=a%100//10
    a10=a%10
    S=[a1,a2,a3,a4,a5,a6,a7,a8,a9,a10]
    
    for y in S:
        k=0 
        for i in range(1,y//2+1):
            if y%i==0:
                k=k+1
        if k==1:
            l=max(l,y)
    print(l)
            
    
